package cn.lyq.card.ui.order

import android.view.View
import android.widget.ImageView
import androidx.core.content.ContextCompat
import cn.lyq.card.R
import cn.lyq.card.data.model.OrderDetailInfo
import cn.lyq.card.utils.loadUrl
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.module.LoadMoreModule
import com.chad.library.adapter.base.viewholder.BaseViewHolder


class OrderListAdapter : BaseQuickAdapter<OrderDetailInfo, BaseViewHolder>
    (R.layout.item_order, mutableListOf()), LoadMoreModule {

    override fun convert(holder: BaseViewHolder, item: OrderDetailInfo) {
        holder.setText(R.id.tvOrderNo, "订单编号：${item.orderNumber ?: ""}")
        val date = item.addTime?.takeIf { it.contains(" ") }?.run { this.split(" ")[0] }
        holder.setText(R.id.tvOrderDate, date ?: "")

        holder.getView<ImageView>(R.id.imgDevice).loadUrl(item.img)
        holder.setText(R.id.tvName, "机具类型：${item.goodsName ?: ""}")
        holder.setText(R.id.tvPrice, "机具价格：${item.goodsPrice ?: ""}元/台")
        holder.getView<View>(R.id.itemDevice).setBackgroundColor(
            ContextCompat.getColor(context, R.color.bg_white)
        )
        holder.getView<View>(R.id.itemDevice).elevation = 0f
        holder.setVisible(R.id.tvBuyDevice, false)

        holder.setText(R.id.tvAmount, "￥${item.totalMoney ?: ""}(共${item.number}台)")
    }

}